package com.community.process._1010.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
订单状态： 1-待确认/待支付，  2-已支付， 3-已发货，  4-超时未支付， 5-已收货，
   6-已完结/确认收货， 7-申请退款中， 8-发货前退款完结， 9-发货后退款完结， 10-收货后退款完结，
   11-退款完结， 12-买家关闭订单，  13-商家关闭订单

 主订单状态：1：未支付；2：已支付；3：买家关闭订单；4：超时未支付；5：商家关闭订单
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {
    TO_BE_PAID(1,1,"待确认/待支付"),
    HAVE_PAID(2,2,"已支付"),
    SHIPPED(3,-1,"已发货"),
    CANCELLED(4,4,"已取消"),
    SIGNED_FOR_RECEIPT(5,-1,"已收货/已签收"),
    COMPLETED(6,-1,"已完结/确认收货"),
    APPLYING_FOR_A_REFUND(7,-1,"申请退款中"),
    REFUND_COMPLETED_BEFORE_DELIVERY(8,-1,"发货前退款完结"),
    REFUND_WILL_BE_COMPLETED_AFTER_DELIVERY(9,-1,"发货后退款完结"),
    REFUND_WILL_BE_COMPLETED_UPON_RECEIPT_OF_GOODS(10,-1,"收货后退款完结"),
    REFUND_COMPLETED(11,-1,"退款完结"),
    USER_CLOSE(12,3,"买家关闭订单"),
    SELLER_CLOSE(13,5,"商家关闭订单"),
    UNKNOWN(999,-1,"未知状态"),
    ;
    private final Integer code;
    private final Integer mainStatus;
    private final String name;

    /**
     * 根据主订单状态转为副业务订单状态
     * @param mainStatus 主订单状态
     * @return OrderStatusEnum
     */
    public static OrderStatusEnum findStatusByMainStatus(Integer mainStatus) {
        for (OrderStatusEnum value : values()) {
            if (value.getMainStatus().equals(mainStatus)) {
                return value;
            }
        }
        return UNKNOWN;
    }

}
